<?php

/*
 * @copyright :     Ienter asia Technologies
 * @author :        Quyet
 * @version         v.1.0
 * @created         18/6/2014
 * @Description :   Controller salary information
 */
if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Mod_salaryinfo extends MYAD_Controller {

    function __construct() {
        parent::__construct();
        $this->load->model('Mmod_salaryinfo', 'sa');
    }

    function index($page = 0) {
        $employeeID = $this->input->post('txtEmployeeId');
        $data = $this->sa->getAllData($employeeID, $page);
        $this->load->view('layout', $data);
    }

    function updateSalaryInfo() {
        $employeeID = $this->input->post('txtEmployeeId');
        $salaryInfoId = $this->input->post('txtSalaryInfoId');

        /* check exists */
        $salaryInfo = TRUE;
        if ($salaryInfoId) {
            $salaryInfo = $this->sa->getSalaryInforByID($employeeID, $salaryInfoId);
        }
        if (!$salaryInfo || !$employeeID) {
            redirect('/employee');
        }

        $temp = array();
        /* check submit */
        if (isset($_POST['btnSubmit'])) {
            $validateFlag = $this->sa->validate();
            if ($validateFlag) {
                /* validate success */
                $temp = $this->sa->updateSalaryInfo($employeeID, $salaryInfoId);
            }
        }

        $data = $this->sa->getAddSalaryInfo($employeeID, $salaryInfoId);
        $this->load->view('layout', array_merge($data, $temp));
    }

}

?>